home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 029a / masview.zip / TTT3.C < prev    next >
Text File  |  1991-10-23  |  1KB  |  47 lines

  1. /* ttt3.c - check for game over */
  2.  
  3. #include "stdio.h"
  4. #include "ttt.h"
  5.  
  6. game_over( bd )        /* check and return true or false */
  7. char bd[ 3 ][ 3 ];
  8. {
  9.     int x, y;
  10.  
  11.     if ( winner( bd ) )
  12.         return( TRUE );
  13.     for ( x = 0; x < 3; ++x )
  14.         for ( y = 0; y < 3; ++y )
  15.             if ( bd[ x ][ y ] == EMPTY )
  16.                 return( FALSE );
  17.     return( TRUE );
  18. }
  19.  
  20. winner( bd )    /* check for a winner on bd[][], return true or false */
  21. char bd[ 3 ][ 3 ];
  22. {
  23.     int x;
  24.  
  25.     for ( x = 0; x < 3; ++x )
  26.     {
  27.         if ( bd[ x ][ 0 ] != EMPTY    /* winner across? */
  28.           && bd[ x ][ 0 ] == bd[ x ][ 1 ]
  29.           && bd[ x ][ 1 ] == bd[ x ][ 2 ] )
  30.             return( TRUE );
  31.         if ( bd[ 0 ][ x ] != EMPTY    /* winner up and down? */
  32.           && bd[ 0 ][ x ] == bd[ 1 ][ x ]
  33.           && bd[ 1 ][ x ] == bd[ 2 ][ x ] )
  34.             return( TRUE );
  35.     }
  36.     if ( bd[ 1 ][ 1 ] != EMPTY )        /* winner diagonally? */
  37.     {
  38.         if ( bd[ 0 ][ 0 ] == bd[ 1 ][ 1 ]
  39.           && bd[ 1 ][ 1 ] == bd[ 2 ][ 2 ] )
  40.             return( TRUE );
  41.         if ( bd[ 0 ][ 2 ] == bd[ 1 ][ 1 ]
  42.           && bd[ 1 ][ 1 ] == bd[ 2 ][ 0 ] )
  43.             return( TRUE );
  44.     }
  45.     return( FALSE );            /* no winner yet */
  46. }
  47.